package com.haojiu.controller;

import com.haojiu.pojo.SmsComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Random;

/**
 * @author:我叫浩九
 * @date：2021/8/31 16:23
 * create in RuGao JiangSu
 */
@Controller
public class SmsController {
    @ResponseBody
    @RequestMapping("/send")
    public String getSms(HttpServletRequest request, HttpServletResponse response) {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        SmsComponent smsComponent = new SmsComponent();
        Random random = new Random();
        String re = "";
        for (int i = 0; i < 6; i++) {
            re += random.nextInt(10);
        }
        System.out.println(re);
        HttpSession session = request.getSession();
        session.setAttribute("captcha", re);
        smsComponent.sendSmsCode("19916949746", re);
        return "send success";

    }
}
